<?php
/* CLAUSES */
require_once(dirname(__FILE__)."/clauses/AbstractSQLClause.php");
require_once(dirname(__FILE__)."/clauses/SQLOptionsClause.php");
require_once(dirname(__FILE__)."/clauses/SQLColumnsClause.php");
require_once(dirname(__FILE__)."/clauses/SQLAliasClause.php");
require_once(dirname(__FILE__)."/clauses/SQLJoinsClause.php");
require_once(dirname(__FILE__)."/clauses/SQLConditionsClause.php");
require_once(dirname(__FILE__)."/clauses/SQLGroupByClause.php");
require_once(dirname(__FILE__)."/clauses/SQLHavingClause.php");
require_once(dirname(__FILE__)."/clauses/SQLOrderByClause.php");
require_once(dirname(__FILE__)."/clauses/SQLLimitClause.php");
require_once(dirname(__FILE__)."/clauses/SQLAlterClause.php");
require_once(dirname(__FILE__)."/clauses/SQLColumnDefinitionClause.php");
require_once(dirname(__FILE__)."/clauses/SQLCreateClause.php");
require_once(dirname(__FILE__)."/clauses/SQLInsertsClause.php");
require_once(dirname(__FILE__)."/clauses/SQLUpdatesClause.php");

/* FIELDS */
require_once(dirname(__FILE__)."/fields/SQLExpression.php");
require_once(dirname(__FILE__)."/fields/SQLValue.php");

/* CONSTANTS */
require_once(dirname(__FILE__)."/constants/SQLComparisonOperators.php");
require_once(dirname(__FILE__)."/constants/SQLLogicalOperators.php");

/**
 * Abstract model for table-specific queries
 */
abstract class AbstractSQLTableQuery {
	protected $strTableName;
	protected $strDatabaseName;
	
	/**
	 * Initializes table.
	 * 
	 * @param string $strDatabaseName
	 * @param string $strTableName
	 */
	public function __construct($strDatabaseName, $strTableName) {
		$this->strDatabaseName = $strDatabaseName;
		$this->strTableName = $strTableName;
	}
	
	protected function getTableName() {
		return $this->strDatabaseName.".".$this->strTableName;
	}
	
	/**
	 * Prototypes a query that alters current table.
	 * SQL: ALTER TABLE {name} {alter_clause}
	 * 
	 * @param SQLAlterClause $objSQLAlterClause
	 */
	abstract public function alter($objSQLAlterClause);
	
	/**
	 * Prototypes a query that creates current table.
	 * SQL: CREATE TABLE {name} {create_clause}
	 * 
	 * Note: the way table type is placed is vendor specific
	 * 
	 * @param SQLCreateClause $objSQLCreateClause
	 * @param string $strTableType
	 */
	abstract public function create($objSQLCreateClause, $strTableType="");
	
	/**
	 * Prototypes a query that renames current table.
	 * SQL: RENAME TABLE {name} to {new_name}
	 * 
	 * @param string $strNewTableName
	 */
	abstract public function rename($strNewTableName);
	
	/**
	 * Prototypes a query that shows columns information for current table
	 * SQL: * (vendor specific)
	 */
	abstract public function describe();
	
	/**
	 * Prototypes a query that drops current table.
	 * SQL: DROP TABLE {name}
	 */
	abstract public function drop();
	
	/**
	 * Prototypes a query that empties current table.
	 * SQL: TRUNCATE TABLE {name}
	 */
	abstract public function truncate();
	
	/**
	 * Prototypes a query that selects from current table.
	 * SQL: SELECT {options_clause} {columns_clause} FROM {name} {joins_clause} {where_clause} {groupBy_clause} {having_clause} {orderBy_clause} {limit_clause}
	 * 
	 * @param SQLOptionsClause $objSQLOptionsClause
	 * @param SQLColumnsClause $objSQLColumnsClause
	 * @param SQLJoinsClause $objSQLJoinsClause
	 * @param SQLConditionsClause $objSQLConditionsClause
	 * @param SQLGroupByClause $objSQLGroupByClause
	 * @param SQLHavingClause $objSQLHavingClause
	 * @param SQLOrderByClause $objSQLOrderByClause
	 * @param SQLLimitClause $objSQLLimitClause
	 */
	abstract public function select($objSQLOptionsClause=null, $objSQLColumnsClause=null, $objSQLJoinsClause=null, $objSQLConditionsClause=null, $objSQLGroupByClause=null, $objSQLHavingClause=null, $objSQLOrderByClause=null, $objSQLLimitClause=null);
	
	/**
	 * Prototypes a query that inserts into current table
	 * SQL: INSERT INTO {name} ({columns_clause}) VALUES {inserts_clause}
	 * 
	 * @param SQLColumnsClause $objSQLColumnsClause
	 * @param SQLInsertsClause $objSQLInsertsClause
	 */
	abstract public function insert($objSQLColumnsClause, $objSQLInsertsClause);
	
	/**
	 * Prototypes a query that updates current table
	 * SQL: UPDATE {name} SET {updates_clause} WHERE {where_clause}
	 * 
	 * @param SQLUpdatesClause $objSQLUpdatesClause
	 * @param SQLConditionsClause $objSQLConditionsClause
	 */
	abstract public function update($objSQLUpdatesClause, $objSQLConditionsClause=null);
	
	/**
	 * Prototypes a query that deletes from current table.
	 * SQL: DELETE FROM {name} WHERE {where_clause}
	 * 
	 * @param SQLConditionsClause $objSQLConditionsClause
	 */
	abstract public function delete($objSQLConditionsClause);
}